import instance from './request'

// 注册
export const reqRegister = (data) => {
  return instance({
    url: '/api/register',
    method: 'post',
    data,
  })
}

// 登录
export const reqLogin = (data) => {
  return instance({
    url: '/api/login',
    method: 'post',
    data,
  })
}

// 上传头像
export const reqUploadAvatar = (formData) => {
  return instance.post('/api/upload', formData)
}

// 获取用户地址
export const reqUserAddressList = () => {
  return instance({
    url: '/api/getaddress/',
  })
}

// 获取用户地址详情
export const reqOneAddress = (address_id) => {
  return instance({
    url: '/api/getoneaddress?address_id=' + address_id,
  })
}

// 添加用户地址
export const reqAddUserAddress = (addressInfo) => {
  return instance({
    method: 'post',
    url: '/api/addaddress/',
    data: addressInfo,
  })
}

// 删除用户地址
export const reqDelUserAddress = (address_id) => {
  return instance({
    method: 'post',
    url: '/api/deladdress?address_id=' + address_id,
  })
}

// 编辑用户地址
export const reqUpdUserAddress = (addressInfo) => {
  return instance({
    method: 'post',
    url: '/api/updateaddress?address_id=' + addressInfo.id,
    data: addressInfo,
  })
}

// 获取购物车商品
export const reqCarGoods = (goods_ids) => {
  return instance({
    url: `/api/getshopcarlist/${goods_ids}`,
  })
}

// 刷新token
export const reqRefreshToken = (refreshToken) => {
  return instance({
    method: 'post',
    url: `/api/refreshToken`,
    data: { refreshToken },
  })
}

// 获取用户历史记录
export const reqHistory = ({ page = 1, pagesize = 10 }) => {
  return instance({
    method: 'get',
    url: `/api/history`,
    params: { page, pagesize },
  })
}

// 添加用户历史记录
export const reqAddHistory = (goods_id) => {
  return instance({
    method: 'post',
    url: `/api/addhistory?goods_id=${goods_id}`,
    // params: { goods_id },
  })
}
